home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample SMSAM / SampleSMSAM Source / ThreadStuff / Threads.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-28  |  5.5 KB  |  172 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Threads.h
  3.  
  4.     Copyright:    © 1991-1994 by Apple Computer, Inc.
  5.                 All rights reserved.
  6.  
  7.     Part of the AOCE Sample SMSAM Package.  Consult the license
  8.     which came with this software for your specific legal rights.
  9.  
  10. */
  11.  
  12.  
  13.  
  14. #ifndef __THREADS__
  15. #define __THREADS__
  16.  
  17. #include <Memory.h>
  18.  
  19. /* Thread Gestalt Selectors */
  20. enum {
  21. #define gestaltThreadMgrAttr    'thds'            /* Thread Manager attributes */
  22.     
  23.     gestaltThreadMgrPresent = 0                    /* bit true if Thread Manager is present */
  24. };
  25.  
  26. /* Thread states */
  27. typedef unsigned short            ThreadState;
  28. #define kReadyThreadState        ((ThreadState) 0)
  29. #define kStoppedThreadState        ((ThreadState) 1)
  30. #define kRunningThreadState        ((ThreadState) 2)
  31.  
  32. /* Thread environment characteristics */
  33. typedef void*    ThreadTaskRef;
  34.  
  35. /* Thread characteristics */
  36. typedef unsigned long            ThreadStyle;
  37. #define kCooperativeThread        (1<<0)
  38. #define kPreemptiveThread        (1<<1)
  39.  
  40. /* Thread identifiers */
  41. typedef unsigned long            ThreadID;
  42. #define kNoThreadID                ((ThreadID) 0)
  43. #define kCurrentThreadID        ((ThreadID) 1)
  44. #define kApplicationThreadID    ((ThreadID) 2)
  45.  
  46. /* Options when creating a thread */
  47. typedef unsigned long            ThreadOptions;
  48. #define kNewSuspend                (1<<0)
  49. #define kUsePremadeThread        (1<<1)
  50. #define kCreateIfNeeded            (1<<2)
  51. #define kFPUNotNeeded            (1<<3)
  52.  
  53. /* Information supplied to the custom scheduler */
  54. struct SchedulerInfoRec {
  55.     unsigned long    InfoRecSize;
  56.     ThreadID        CurrentThreadID;
  57.     ThreadID        SuggestedThreadID;
  58.     ThreadID        InterruptedCoopThreadID;
  59. };
  60. typedef struct SchedulerInfoRec SchedulerInfoRec;
  61. typedef SchedulerInfoRec *SchedulerInfoRecPtr;
  62.  
  63. /* Prototype for thread's entry (main) routine */
  64. typedef pascal void *            (ThreadEntryProc)(void *threadParam);
  65. typedef ThreadEntryProc            *ThreadEntryProcPtr;
  66.  
  67. /* Prototype for custom thread scheduler routine */
  68. typedef pascal ThreadID            (ThreadSchedulerProc)(SchedulerInfoRecPtr schedulerInfo);
  69. typedef ThreadSchedulerProc        *ThreadSchedulerProcPtr;
  70.  
  71. /* Prototype for custom thread switcher routine */
  72. typedef pascal void                (ThreadSwitchProc)(ThreadID threadBeingSwitched, void *switchProcParam);
  73. typedef ThreadSwitchProc        *ThreadSwitchProcPtr;
  74.  
  75. /* Prototype for thread termination notification routine */
  76. typedef pascal void                (ThreadTerminationProc)(ThreadID threadTerminated, void *terminationProcParam);
  77. typedef ThreadTerminationProc    *ThreadTerminationProcPtr;
  78.  
  79. /* Prototype for debugger NewThread notification */
  80. typedef pascal void                    (DebuggerNewThreadProc)(ThreadID threadCreated);
  81. typedef DebuggerNewThreadProc        *DebuggerNewThreadProcPtr;
  82.  
  83. /* Prototype for debugger DisposeThread notification */
  84. typedef pascal void                    (DebuggerDisposeThreadProc)(ThreadID threadDeleted);
  85. typedef DebuggerDisposeThreadProc        *DebuggerDisposeThreadProcPtr;
  86.  
  87. /* Prototype for debugger schedule notification */
  88. typedef pascal ThreadID                (DebuggerThreadSchedulerProc)(SchedulerInfoRecPtr schedulerInfo);
  89. typedef DebuggerThreadSchedulerProc    *DebuggerThreadSchedulerProcPtr;
  90.  
  91. /* Errors */
  92. enum {
  93.     threadTooManyReqsErr    = -617,
  94.     threadNotFoundErr        = -618,
  95.     threadProtocolErr        = -619
  96. };
  97.  
  98. /* Thread Manager routines */
  99. pascal OSErr CreateThreadPool(ThreadStyle threadStyle, short numToCreate, Size stackSize)
  100.     = {0x303C,0x0501,0xABF2};
  101.  
  102. pascal OSErr GetFreeThreadCount(ThreadStyle threadStyle, short *freeCount)
  103.     = {0x303C,0x0402,0xABF2};
  104.  
  105. pascal OSErr GetDefaultThreadStackSize(ThreadStyle threadStyle, Size *stackSize)
  106.     = {0x303C,0x0413,0xABF2};
  107.  
  108. pascal OSErr ThreadCurrentStackSpace(ThreadID thread, unsigned long *freeStack)
  109.     = {0x303C,0x0414,0xABF2};
  110.  
  111. pascal OSErr NewThread(    ThreadStyle threadStyle,
  112.                         ThreadEntryProcPtr threadEntry,
  113.                         void *threadParam,
  114.                         Size stackSize,
  115.                         ThreadOptions options,
  116.                         void **threadResult,
  117.                         ThreadID *threadMade)
  118.     = {0x303C,0x0E03,0xABF2};
  119.  
  120. pascal OSErr DisposeThread(ThreadID threadToDump, void *threadResult, Boolean recycleThread)
  121.     = {0x303C,0x0504,0xABF2};
  122.  
  123. pascal OSErr YieldToThread(ThreadID suggestedThread)
  124.     = {0x303C,0x0205,0xABF2};
  125.  
  126. pascal OSErr YieldToAnyThread(void)
  127.     = {0x42A7,0x303C,0x0205,0xABF2};
  128.  
  129. pascal OSErr GetCurrentThread(ThreadID *currentThreadID)
  130.     = {0x303C,0x0206,0xABF2};
  131.  
  132. pascal OSErr GetThreadState(ThreadID threadToGet, ThreadState *threadState)
  133.     = {0x303C,0x0407,0xABF2};
  134.  
  135. pascal OSErr SetThreadState(ThreadID threadToSet, ThreadState newState, ThreadID suggestedThread)
  136.     = {0x303C,0x0508,0xABF2};
  137.  
  138. pascal OSErr SetThreadStateEndCritical(ThreadID threadToSet, ThreadState newState, ThreadID suggestedThread)
  139.     = {0x303C,0x0512,0xABF2};
  140.  
  141. pascal OSErr SetThreadScheduler(ThreadSchedulerProcPtr threadScheduler)
  142.     = {0x303C,0x0209,0xABF2};
  143.  
  144. pascal OSErr SetThreadSwitcher(ThreadID thread, ThreadSwitchProcPtr threadSwitcher, void *switchProcParam, Boolean inOrOut)
  145.     = {0x303C,0x070A,0xABF2};
  146.  
  147. pascal OSErr SetThreadTerminator(ThreadID thread, ThreadTerminationProcPtr threadTerminator, void *terminationProcParam)
  148.     = {0x303C,0x0611,0xABF2};
  149.  
  150. pascal OSErr ThreadBeginCritical(void)
  151.     = {0x303C,0x000B,0xABF2};
  152.  
  153. pascal OSErr ThreadEndCritical(void)
  154.     = {0x303C,0x000C,0xABF2};
  155.  
  156. pascal OSErr SetDebuggerNotificationProcs (    DebuggerNewThreadProcPtr notifyNewThread,
  157.                                             DebuggerDisposeThreadProcPtr notifyDisposeThread,
  158.                                             DebuggerThreadSchedulerProcPtr notifyThreadScheduler)
  159.     = {0x303C,0x060D,0xABF2};
  160.  
  161. pascal OSErr GetThreadCurrentTaskRef (ThreadTaskRef *threadTRef)
  162.     = {0x303C,0x020E,0xABF2};
  163.  
  164. pascal OSErr GetThreadStateGivenTaskRef (ThreadTaskRef threadTRef, ThreadID threadToGet, ThreadState *threadState)
  165.     = {0x303C,0x060F,0xABF2};
  166.  
  167. pascal OSErr SetThreadReadyGivenTaskRef (ThreadTaskRef threadTRef, ThreadID threadToSet)
  168.     = {0x303C,0x0410,0xABF2};
  169.  
  170.  
  171. #endif /* __THREADS__ */
  172.